package com.chenchao.javafile;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/15 14:00
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.javaFile.Test54.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 字符流
 */
public class Test4 {
    public static void main(String[] args) throws IOException {
        //test1();
        test2();
    }
    public static void test1() throws IOException {
        //构造方法
        File file = new File("myjava01/src/fo/aa.txt");
        FileReader fileReader1 = new FileReader(file);
        FileReader fileReader = new FileReader("myjava01/src/fo/aa.txt");

        //读取方法
        //读取一个字符,结果为int型
        int read = fileReader.read();
        System.out.println(read);
        System.out.println((char) read);
        //转成char类型
        System.out.println((char)fileReader.read());
        //读取到最后一个是-1
    }

    /**
     * while读入字符
     * @throws IOException IO
     */
    public static void test2() throws IOException {
        File file = new File("myjava01/src/fo/aa.txt");
        FileReader fileReader1 = new FileReader(file);
        int i=0;
        while((i=fileReader1.read())!=-1){
            System.out.print((char)i);
        }
    }
    public static void test3(){

    }
}
